#pragma once
//============================================================================
// Copyright (C) 2003-2013 Brett R. Jones
//
// Issued to public domain 2013
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================

#define VX_DEFS 1

// uncomment for debugging
//#define DEBUG_MUTEXES 1
//#define DEBUG_SKTS 1
#define DEBUG_CONNECTIONS 1
#define DEBUG_CONNECT_LIST 1
#define DEBUG_RELAY 1
//#define DEBUG_PKTS 1

//============================================================================
// common type defines
//============================================================================
#define S8	char
#define U8	unsigned char
#define S16	short
#define U16	unsigned short
#define S32	long
#define U32	unsigned long
#define F32	float
#define F64	double

#ifdef WIN_PLATFORM // windows
	#define WIN32_LEAN_AND_MEAN 1
	#include <windows.h>
    #pragma warning( disable: 4100 )

    #define RCODE long
	#define S64	__int64
	#define U64	unsigned __int64
    #ifndef _WINDEF_
        typedef unsigned long       DWORD;
        typedef int                 BOOL;
        typedef unsigned char       BYTE;
        typedef unsigned short      WORD;
        typedef float               FLOAT;
        typedef int                 INT;
        typedef unsigned int        UINT;
    #endif
	// sleep specified milliseconds
	#define VxSleep(exp)		Sleep(exp) 
	#define VxGetLastError		GetLastError
	#define mkdir(exp,exp2)		_mkdir(exp)     //make directory command we can use in windows like linux
#else // LINUX or ANDROID
    #include <errno.h>
    #ifndef TRUE
        #define TRUE 1
    #endif // TRUE
    #ifndef FALSE
        #define FALSE 0
    #endif // FALSE
    #ifndef NULL
        #define NULL 0
    #endif // NULL
    #define RCODE long
    #define wxChar char
    #define INT int
	#define UINT unsigned int
    #define BOOL int
    #define CHAR char
	#define UCHAR unsigned char
    #define BYTE unsigned char
    #define SHORT short
	#define USHORT unsigned short
    #define WORD unsigned short
    #define LONG long
	#define ULONG unsigned long
    #define DWORD unsigned long
	#define S64	long long
	#define U64	unsigned long long

    #include <unistd.h>

	// some missing functions in linux
    #include "VxLinuxOnly.h"

	//VxSleep.. sleep specified milliseconds
    #ifdef ANDROID_PLATFORM
		#include <time.h>
		// android doesnt have millisleep like most linux distributions but does have nano sleep
		inline void VxSleep( int iMilliSec )
		{
			timespec ts;
			ts.tv_sec = iMilliSec/1000;
			ts.tv_nsec = (iMilliSec%1000)*1000000;
			nanosleep(&ts, NULL);
		};		
	#else // android
		// normal linux
		//#define VxSleep(exp)		msleep(exp)
		#define VxSleep(exp)		usleep(exp * 1000)
	#endif //ANDROID_PLATFORM

    #define     VxGetLastError()	errno
    #define     HWND				void *
    #define     MAX_PATH			512
    #define     SOCKET				int		// use windows style socket define
    #define     INVALID_SOCKET		-1		// use windows style socket define
    #define     SOCKET_ERROR		-1		// use windows style socket define

#endif //LINUX

#pragma pack(push) 
#pragma pack(1)
typedef union U128
{
	struct 
	{
		U64  u64HiPart;
		U64  u64LoPart;
	};
	U8 m_u128AsBytes[16];
} U128;
#pragma pack(pop)


#ifndef RCODE
	#define RCODE	S32
#endif

#ifndef WIN_PLATFORM
    #ifdef ANDROID_PLATFORM
        #ifndef max
            #define max(a,b)            (((a) > (b)) ? (a) : (b))
        #endif

        #ifndef min
            #define min(a,b)            (((a) < (b)) ? (a) : (b))
        #endif
    #endif // ANDROID_PLATFORM
#endif

